

from time import sleep

import pytest
import yaml
from selenium import webdriver



#添加成员页面
from selenium.webdriver.common.by import By

from webselenium0617.po.basepage import BasePage


class AddMemberPage(BasePage):
    _USERNAME = (By.ID, "username")
    _MEMBERADDENGLINSHNAME = (By.ID, "memberAdd_english_name")
    _MEMBERADDACCTID = (By.ID,"memberAdd_acctid")
    _MEMBERADDPHONE = (By.ID, "memberAdd_phone")
    _SAVE = ((By.CSS_SELECTOR,".js_btn_save"))

    def edit_member(self,name, mail, tel):
        #添加后，返回到通讯录页面对象
        from webselenium0617.po.contact_page import ContactPage
        # 优化重复代码，将浏览器复用在basepage中定义
        # opt = webdriver.ChromeOptions()
        # opt.debugger_address = "127.0.0.1:9222"
        # self.driver = webdriver.Chrome(options=opt)
        # self.driver.implicitly_wait(5)

        # self.driver.find_element_by_id("username").send_keys("yaofeng5")
        # self.driver.find_element_by_id("memberAdd_english_name").send_keys("yf5")
        # self.driver.find_element_by_id("memberAdd_acctid").send_keys("yaofeng2@163.com")
        # self.driver.find_element_by_id("memberAdd_phone").send_keys("18964342871")


        # 优化代码，使用在basepage中封装的方法
        # self.find(By.ID, "username").send_keys("yaofeng5")
        # self.find(By.ID, "memberAdd_english_name").send_keys("yf5")
        # self.find(By.ID, "memberAdd_acctid").send_keys("yaofeng2@163.com")
        # self.find(By.ID, "memberAdd_phone").send_keys("18964342871")

        self.find(*self._USERNAME).send_keys("yaofeng5")
        self.find(*self._MEMBERADDENGLINSHNAME).send_keys("yf5")
        self.find(*self._MEMBERADDACCTID).send_keys("yaofeng2@163.com")
        self.find(*self._MEMBERADDPHONE).send_keys("18964342871")

        self.driver.execute_script('document.documentElement.scrollTop=2000')
        sleep(2)

        # self.driver.find_element_by_link_text("保存").click()
        # self.driver.find_element_by_css_selector(".js_btn_save").click()
        # self.find_and_click(".js_btn_save")
        self.find_and_click(*self._SAVE)
        sleep(8)

        return ContactPage(self.driver)

